﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

namespace ProjectSem3
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                EmpRegister Semp = (EmpRegister)Session["member"];
                if (Semp == null)
                {
                    Response.Redirect("member.aspx");
                }
                else
                {
                    Baokq.Visible = false;
                    ulkq.Visible = true;
                    this.TextBox1.Text = Semp.username;

                    this.DropDownListPolicy.DataSource = dc.policies;
                    this.DropDownListPolicy.DataValueField = "policyid";
                    this.DropDownListPolicy.DataTextField = "policyname";
                    this.DropDownListPolicy.DataBind();

                    this.DropDownListCompany.DataSource = dc.CompanyDetails;
                    this.DropDownListCompany.DataValueField = "companyid";
                    this.DropDownListCompany.DataTextField = "companyname";
                    this.DropDownListCompany.DataBind();
                    
                }
            }
        }

        protected void ButtonBuy_Click(object sender, EventArgs e)
        {
            EmpRegister Semp = (EmpRegister)Session["member"];
            int empno = Semp.empno;
            string requestdate = DateTime.Now.ToShortDateString();
            string policyid = DropDownListPolicy.SelectedValue.ToString();
            string companyid = DropDownListCompany.SelectedValue.ToString();
            string status = "no";
            string pstartdate = this.datestart.Value;
            string penddate = this.dateend.Value;
            order(requestdate, empno, policyid, companyid, status, pstartdate, penddate);
            Baokq.Visible = true;
            ulkq.Visible = false;

        }

        public void order(string requestdate, int empno, string policyid, string companyid, string status, string pstartdate, string penddate)
        {
            PolicyRequestDetail prd = new PolicyRequestDetail();
            prd.requestdate = Convert.ToDateTime(requestdate);
            prd.empno = empno;
            prd.policyid = Convert.ToInt32(policyid);
            prd.companyid = Convert.ToInt32(companyid);
            prd.status = status;
            this.dc.PolicyRequestDetails.InsertOnSubmit(prd);
            this.dc.SubmitChanges();
            int newID = prd.requestid;

            policiesonemployee ple = new policiesonemployee();
            ple.pstartdate = Convert.ToDateTime(pstartdate);
            ple.penddate = Convert.ToDateTime(penddate);
            ple.requestid = newID;
            this.dc.policiesonemployees.InsertOnSubmit(ple);
            this.dc.SubmitChanges();


        }
       
    }
}